package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AlertConfiguration;
import com.ruoyi.system.service.IAlertConfigurationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * configurationController
 * 
 * @author ruoyi
 * @date 2025-02-18
 */
@RestController
@RequestMapping("/system/configuration")
public class AlertConfigurationController extends BaseController
{
    @Autowired
    private IAlertConfigurationService alertConfigurationService;

    /**
     * 查询configuration列表
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:list')")
    @GetMapping("/list")
    public TableDataInfo list(AlertConfiguration alertConfiguration)
    {
        startPage();
        List<AlertConfiguration> list = alertConfigurationService.selectAlertConfigurationList(alertConfiguration);
        return getDataTable(list);
    }

    /**
     * 导出configuration列表
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:export')")
    @Log(title = "configuration", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlertConfiguration alertConfiguration)
    {
        List<AlertConfiguration> list = alertConfigurationService.selectAlertConfigurationList(alertConfiguration);
        ExcelUtil<AlertConfiguration> util = new ExcelUtil<AlertConfiguration>(AlertConfiguration.class);
        util.exportExcel(response, list, "configuration数据");
    }

    /**
     * 获取configuration详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:query')")
    @GetMapping(value = "/{alertId}")
    public AjaxResult getInfo(@PathVariable("alertId") Long alertId)
    {
        return success(alertConfigurationService.selectAlertConfigurationByAlertId(alertId));
    }

    /**
     * 新增configuration
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:add')")
    @Log(title = "configuration", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlertConfiguration alertConfiguration)
    {
        return toAjax(alertConfigurationService.insertAlertConfiguration(alertConfiguration));
    }

    /**
     * 修改configuration
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:edit')")
    @Log(title = "configuration", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlertConfiguration alertConfiguration)
    {
        return toAjax(alertConfigurationService.updateAlertConfiguration(alertConfiguration));
    }

    /**
     * 删除configuration
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:remove')")
    @Log(title = "configuration", businessType = BusinessType.DELETE)
	@DeleteMapping("/{alertIds}")
    public AjaxResult remove(@PathVariable Long[] alertIds)
    {
        return toAjax(alertConfigurationService.deleteAlertConfigurationByAlertIds(alertIds));
    }
}
